package com.rdxy.mult.controller;

import com.rdxy.common.utils.OssTemplate;
import com.rdxy.common.utils.VodTemplate;
import com.rdxy.common.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/upload")
public class UploadController {

    @Autowired
    private OssTemplate ossTemplate;

    @Autowired
    private VodTemplate vodTemplate;


    //图片上传
    @PostMapping("/image")
    public Result<Map<String,Object>> uploadImage(@RequestPart("file") MultipartFile uploadImage) throws IOException {
        String imgPath = ossTemplate.upload(uploadImage.getOriginalFilename(), uploadImage.getInputStream());
        System.out.println(imgPath);

        Map<String,Object> data=new HashMap<>();
        data.put("image",imgPath);
        return Result.success(data);
    }

    //影片上传
    @PostMapping("/video")
    public Result<Map<String,Object>> uploadVideo(@RequestPart("file") MultipartFile uploadVideo) throws IOException {
        String videoId = vodTemplate.uploadVideo(uploadVideo.getOriginalFilename(), uploadVideo.getInputStream());
        System.out.println(videoId);

        Map<String,Object> data=new HashMap<>();
        data.put("video",videoId);
        return Result.success(data);
    }
}
